//
//  Help.m
//  EquiriesProject
//
//  Created by qianfeng on 15/10/31.
//  Copyright (c) 2015年 HXH. All rights reserved.
//

#import "Help.h"

@implementation Help

+(NSString*)pathWithBasicPath:(NSString*)basicPath andDic:(NSDictionary*)dic
{
    
    if (dic == nil) {
        return basicPath;
    }
    
    NSMutableArray * keyValueArr = [NSMutableArray array];
    
    for (NSString * key in dic.keyEnumerator) {
        
        NSLog(@"%@  %@",key,dic[key]);
        NSString * KeyAndValue = [NSString stringWithFormat:@"%@=%@",key,dic[key]];
        NSLog(@"%@",KeyAndValue);
        [keyValueArr addObject:KeyAndValue];
    }
    
    NSString * path = [keyValueArr componentsJoinedByString:@"&"];
    
    path = [NSString stringWithFormat:@"%@?%@",basicPath,path];
    
    return path;
}

+(NSString*)getValueWithInfo:(NSString*)infoStr andKey:(NSString*)key
{
    //1.应该先搜索key的范围 ,{location,length}
    
    NSRange keyRange = [infoStr rangeOfString:key];
    
    //2.location + length
    
    NSInteger valueLocation = keyRange.location + keyRange.length;
    
    //3.从2中的位置开始切割到最后,valueStr
    NSString * valueStr = [infoStr substringFromIndex:valueLocation];
    
    //4.搜索valueStr中第一个&符号的位置
    NSRange range = [valueStr rangeOfString:@"&"];
    
    if (range.location == NSNotFound) {
        return valueStr;
    }
    
    //5.直接切割到&符号的位置就行
    NSInteger location = range.location;
    NSString * value = [valueStr substringToIndex:location];
    
    
    return value;
}

+(BOOL)isExpireIn
{
    NSDate * futherDate = [[NSUserDefaults standardUserDefaults] objectForKey:EXPIRES_IN];
    NSDate * currentDate = [NSDate date];
    
    NSComparisonResult result = [currentDate compare:futherDate];
    
    if (result == NSOrderedAscending) {
        return NO;
    }
    
    return YES;
}

@end
